package plugin;

import javax.media.j3d.AmbientLight;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.Bounds;
import javax.media.j3d.Light;
import javax.media.j3d.Node;
import javax.media.j3d.PointLight;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Point3f;

import render.LightingSetup;

public class LightingSetup_003 extends LightingSetup {


	public void setup(Bounds lightBounds) {
		super.setup(lightBounds);
		Color3f light0Color = new Color3f(1f, 1f, 1f);
		Point3f light0Attenuation = new Point3f(1f/0.4f, 0.0f, 0.0f);
		Point3f light0Position = new Point3f();
		PointLight light0 = new PointLight(light0Color, light0Position, light0Attenuation);
		setPointLigthCapabilities(light0);
		lights.put(NODE_LIGHT_ + "0", light0);
		
		Color3f light1Color = new Color3f(1f, 1f, 1f);
		Point3f light1Attenuation = new Point3f(1f/0.5f, 0.0f, 0.0f);
		Point3f light1Position = new Point3f();
		PointLight light1 = new PointLight(light1Color, light1Position, light1Attenuation);
		setPointLigthCapabilities(light1);
		lights.put(NODE_LIGHT_ + "1", light1);
		
		Color3f light2Color = new Color3f(1f, 1f, 1f);
		Point3f light2Attenuation = new Point3f(1f/0.4f, 0.0f, 0.0f);
		Point3f light2Position = new Point3f();
		PointLight light2 = new PointLight(light2Color, light2Position, light2Attenuation);
		setPointLigthCapabilities(light2);
		lights.put(NODE_LIGHT_ + "2", light2);
		
		Color3f ambientLightColor = new Color3f(0.2f, 0.2f, 0.2f);
		AmbientLight ambientLight = new AmbientLight(ambientLightColor);
		ambientLight.setInfluencingBounds(lightBounds);
		ambientLight.setCapability(Node.ALLOW_BOUNDS_READ);
		lights.put("AMBIENT", ambientLight);
	}


	public void updateLights(Bounds lightBounds) {
		super.updateLights(lightBounds);
		double boundsRadius = ((BoundingSphere)lightBounds).getRadius();
		double boundsRadiusForPosition = boundsRadius * 5;
		Point3d boundsCenter = new Point3d();
		((BoundingSphere)lightBounds).getCenter(boundsCenter);
		
		BoundingSphere bounds = new BoundingSphere();
		bounds.setCenter(boundsCenter);
		bounds.setRadius(boundsRadiusForPosition);
		
		double angle0 = 120;
		double angle1 = 240;
		double angle2 = -45;

		Light light0 = lights.get(NODE_LIGHT_ + "0");
		light0.setInfluencingBounds(bounds);
		Point3f newPosition0 = new Point3f((float)boundsCenter.x + (float)((boundsRadius*1.5) * (Math.cos(Math.toRadians(angle0)))), 
				(float)boundsCenter.y + (float)((boundsRadius*1.5) * (Math.sin(Math.toRadians(angle0)))),
				(float)boundsCenter.z + (float)boundsRadius);
		((PointLight) light0).setPosition(newPosition0);
		light0.setEnable(true);
		
		Light light1 = lights.get(NODE_LIGHT_ + "1");
		light1.setInfluencingBounds(bounds);
		Point3f newPosition1 = new Point3f((float)boundsCenter.x + (float)((boundsRadius*1.5) * (Math.cos(Math.toRadians(angle1)))), 
				(float)boundsCenter.y + (float)((boundsRadius*1.5) * (Math.sin(Math.toRadians(angle1)))), 
//				(float)boundsCenter.z + (float)boundsRadius);
				(float)boundsCenter.z);
		((PointLight) light1).setPosition(newPosition1);
		light1.setEnable(true);
		
		Light light2 = lights.get(NODE_LIGHT_ + "2");
		light2.setInfluencingBounds(bounds);
//		Point3f newPosition2 = new Point3f((float)boundsCenter.x + (float)(boundsRadius * (Math.cos(Math.toRadians(angle2)))), 
//				(float)boundsCenter.y + (float)(boundsRadius * (Math.sin(Math.toRadians(angle2)))), 
//				(float)boundsCenter.z - (float)boundsRadius);
		Point3f newPosition2 = new Point3f((float)boundsCenter.x + (float)(boundsRadius * 1.5), 
				(float)boundsCenter.y + (float)(boundsRadius * 1.5), 
				(float)boundsCenter.z - (float)boundsRadius);
		((PointLight) light2).setPosition(newPosition2);
		light2.setEnable(true);
	}

}

